﻿# 指定CMake最低版本
cmake_minimum_required (VERSION 3.12)

# 如果支持，为 MSVC 编译器启用热重载。
if (POLICY CMP0141)
  cmake_policy(SET CMP0141 NEW)
  set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()

# 设置工程名称
project ("algorithm")

# 设置可执行文件输出路径
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${PROJECT_SOURCE_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${PROJECT_SOURCE_DIR}/bin")

# 增加可执行目标。
add_executable(algorithm)

# 将当前目录下所有cpp、h文件添加到变量sources中
file(GLOB sources CONFIGURE_DEPENDS *.cpp *.h)

# 向指定目标增加源代码列表
target_sources(algorithm PUBLIC ${sources})

# 在CMake中启用预编译头文件
target_precompile_headers(algorithm PUBLIC stdafx.h)

# 设置DEBUG模式增加后缀d
set_property(TARGET algorithm PROPERTY DEBUG_POSTFIX d)	

# 关闭release下生成的manifest文件
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /MANIFEST:NO")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /MANIFEST:NO")

# 设置c++标准版本
set_property(TARGET algorithm PROPERTY CXX_STANDARD 11)
